package com.bizprocess;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.EngineServices;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.runtime.Execution;

public class SignalEventListener implements JavaDelegate {

	public void execute(DelegateExecution execution) throws Exception {
		EngineServices engineServices = execution.getEngineServices();
		RuntimeService runtimeService = engineServices.getRuntimeService();
		HistoryService historyService = engineServices.getHistoryService();
		String result = "true";
		Map<String, Object> vars = new HashMap<String, Object>();
		vars.put("result", result);
		
      
		List<Execution> list = runtimeService.createExecutionQuery()
				.processDefinitionKey("signalEventTest")
				.activityId("signalintermediatecatchevent1").list();
		/*// 第一个流程的执行流
		Execution execution1 = runtimeService.createExecutionQuery()
				.processInstanceId(processInstance.getId())
				.activityId("signalintermediatecatchevent1").singleResult();
		// 第二个流程的执行流
		Execution execution2 = runtimeService.createExecutionQuery()
				.processInstanceId(processInstance1.getId())
				.activityId("signalintermediatecatchevent1").singleResult();*/
        Execution execution0=list.get(0);
//		runtimeService.signalEventReceived("end", execution0.getId(), vars);
        runtimeService.signal(execution0.getId(), vars);
//		result="false";
//		Map<String, Object> vars1 = new HashMap<String, Object>();
//		vars1.put("result", result);
		runtimeService.signalEventReceived("end", list.get(1).getId(), vars);
	}

}
